<?php

//<editor-fold defaultstate="collapsed" desc="License & Copyright">
/*
 * @license
 */

/**
 *
 * @author Jevgeni Geimanen (jevgeni.geimanen@gmail.com)
 */
//</editor-fold>
class SCArrayHelper {
    /**
     * 
     * Enter description here ...
     * @param $array array
     * @param $keys array
     * @param $value object
     * @return void
     */
    public static function createArrayKeysTree(&$array, $keys, $value = null, $valueIsPushable = true) {
        $currentKey = &$array;
        if ($valueIsPushable) {
            for ($i = 0; $i < count($keys); $i++) {
                if (!isset($currentKey[$key = $keys[$i]]))
                    $currentKey[$key] = array();
                $currentKey = &$currentKey[$key];
            }
            if ($value !== null)
                $currentKey[] = $value;
        } else {
            if (($lastKeyIndex = count($keys) - 1) > 0) {
                for ($i = 0; $i < $lastKeyIndex; $i++) {
                    if (!isset($currentKey[$key = $keys[$i]]))
                        $currentKey[$key] = array();
                    $currentKey = &$currentKey[$key];
                }
            }
            if ($value !== null)
                $currentKey[$keys[$lastKeyIndex]] = $value;
        }
    }
}

?>
